# -*- coding: utf-8 -*-
from abc import ABCMeta, abstractmethod

class Slippage(object):
    """
    滑点
    """
    __metaclass__ = ABCMeta

    @abstractmethod
    def get_trade_price(self):
        raise NotImplementedError("should implement get_trade_price()")

# 零滑点
class ZeroSlippage(Slippage):
    def get_trade_price(self, price):
        return price

# 固定百分比的滑点
class FixedPercentSlippage(Slippage):
    def __init__(self, percent=0.1):
        self.rate = percent / 100.0

    def get_trade_price(self, price, direction):
        slippage = price * self.rate * (1 if direction == 'BUY' else -1)
        price = price + slippage

        return price

# 根据成交量的滑点
class VolumeSHareSlippage(Slippage):
    def get_trade_price(self, price, direction):
        pass

